package model;

import java.io.*;
import java.util.*;
import com.google.gson.*;

public class Project {
    private int no;
    private String title;
    private String des;
    private List<String> infos;

    public Project(int no, String title, String des, List<String> infos) {
        this.no = no;
        this.title = title;
        this.des = des;
        this.infos = infos;
    }

    // Getter 方法
    public int getNo() {
        return no;
    }

    public String getTitle() {
        return title;
    }

    public String getDes() {
        return des;
    }

    public List<String> getInfos() {
        return infos;
    }

    // 从 JSON 文件加载项目列表
    public static List<Project> loadProjects(String filePath, int totalGroups) throws IOException {
        List<Project> projectList = new ArrayList<>();
        Gson gson = new Gson();

        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
        Project[] projects = gson.fromJson(reader, Project[].class);
        reader.close();

        // 取前 totalGroups 个项目
        for (int i = 0; i < totalGroups && i < projects.length; i++) {
            projectList.add(projects[i]);
        }

        return projectList;
    }
}
